package com.example.hj.controller;


import com.example.hj.entity.NewsInfo;
import com.example.hj.service.INewsInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author huangjian
 * @since 2019-06-28
 */
@Controller
@RequestMapping("/school/news-info")
public class NewsInfoController {

    @Autowired
    private INewsInfoService newsInfoService;

    @RequestMapping(value = "/list")
    public String list(Model model) {
        System.out.println("news-info-list============= " );
        List<NewsInfo> list = newsInfoService.list();
        for (NewsInfo newsInfo:list) {
            System.out.println(newsInfo.getTitle()+"--------"+newsInfo.getAddTime());
        }
        model.addAttribute("newsinfos", list);
        return "/school/newsinfo/list";
    }

    @RequestMapping(value = "/show")
    @ResponseBody
    public NewsInfo show(Model model) {
        System.out.println("news-info-show============= " );
        return newsInfoService.getById(2);
    }
}
